﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Petra.Gis.ImagingServices.Tiff
{
  public partial class ImageFileDirectory
  {

    internal void preparePhotometric(Tag tag)
    {

      //double dd;
      //uint aa;
      //int bb;
      //byte[] eva = new byte[8];
      //int startPtr;
      //byte[] src;

      //startPtr = 0;

      //while (true)
      //{
      //  src = BitConverter.GetBytes(System.Convert.ToUInt16(_tags[TagType.INTERGRAPH_MAINIMAGE].TagData[startPtr]));
      //  Array.Copy(src, 0, eva, 0, 2);

      //  src = BitConverter.GetBytes(System.Convert.ToUInt16(_tags[TagType.INTERGRAPH_MAINIMAGE].TagData[startPtr + 1]));
      //  Array.Copy(src, 0, eva, 2, 2);

      //  src = BitConverter.GetBytes(System.Convert.ToUInt16(_tags[TagType.INTERGRAPH_MAINIMAGE].TagData[startPtr + 2]));
      //  Array.Copy(src, 0, eva, 4, 2);

      //  src = BitConverter.GetBytes(System.Convert.ToUInt16(_tags[TagType.INTERGRAPH_MAINIMAGE].TagData[startPtr + 3]));
      //  Array.Copy(src, 0, eva, 6, 2);

      //  dd = BitConverter.ToDouble(eva, 0);
      //  aa = BitConverter.ToUInt32(eva, 0);
      //  bb = BitConverter.ToInt32(eva, 0);
      //  startPtr += 4;
      //}


      //int bitsPerPixel = Convert.ToInt32(_tags[TagType.BITSPERSAMPLE].TagData[0]);
      //PlanarConfigurationType planarConfiguration = (PlanarConfigurationType)_tags[TagType.PLANARCONFIG].TagData[0];
      //PhotometricType photometricInterpretation = (PhotometricType)tag.Offset;

      //if (tag.Count != 1 || !tag.isInt())
      //{
      //  throw new InvalidFileStructureException("Expected " +
      //    "single byte/short/long value for photometric interpretation.");
      //}

      //// do more checks based on color type
      //switch ((PhotometricType)tag.Offset)
      //{
      //  case (PhotometricType.BlackIsZero):
      //  case (PhotometricType.WhiteIsZero):
      //    {
      //      if (((int)_tags[TagType.BITSPERSAMPLE].TagData[0]) == 1)
      //      {
      //        //imageType = ImageType.BILEVEL_PACKED;
      //      }
      //      else
      //      {
      //        if (((int)_tags[TagType.BITSPERSAMPLE].TagData[0]) == 4)
      //        {
      //          //imageType = ImageType.GRAY4;
      //        }
      //        else
      //          if (((int)_tags[TagType.BITSPERSAMPLE].TagData[0]) == 8)
      //          {
      //            //imageType = ImageType.GRAY8;
      //          }
      //          else
      //          {
      //            throw new UnsupportedTypeException("Only bit depths 1, 4 and 8 are supported for bilevel and grayscale images.");
      //          }
      //      }
      //      break;
      //    }
      //  case (PhotometricType.PALETTED):
      //    {
      //      GetTag(TagType.COLORMAP);
      //      break;
      //    }
      //  case (PhotometricType.TruecolorRGB):
      //    {
      //      if (planarConfiguration != PlanarConfigurationType.Contignous)
      //      {
      //        throw new UnsupportedTypeException("Cannot handle planar configuration other than chunky for RGB images.");
      //      }
      //      if (_tags[TagType.BITSPERSAMPLE].Count != 3)
      //      {
      //        throw new UnsupportedTypeException("Found RGB truecolor image, but instead of three " + _tags[TagType.BITSPERSAMPLE].Count + " component(s).");
      //      }
      //      if (bitsPerPixel == 24)
      //      {
      //        //imageType = ImageType.RGB24_INTERLEAVED;
      //      }
      //      else
      //        if (bitsPerPixel == 48)
      //        {
      //          //imageType = ImageType.RGB48_INTERLEAVED;
      //        }
      //        else
      //        {
      //          throw new UnsupportedTypeException("Unsupported RGB truecolor image color depth: " + bitsPerPixel + ".");
      //        }
      //      break;
      //    }
      //  case (PhotometricType.TRUECOLOR_LOGLUV):
      //    {
      //      if (planarConfiguration == PlanarConfigurationType.Contignous)
      //      {
      //        //imageType = ImageType.LOGLUV32_INTERLEAVED;
      //      }
      //      else
      //      {
      //        throw new UnsupportedTypeException("Cannot handle planar configuration other than chunky for RGB images.");
      //      }
      //      break;
      //    }
      //  case (PhotometricType.LOGL):
      //    {
      //      //imageType = ImageType.LOGL;
      //      break;
      //    }
      //  case (PhotometricType.TRUECOLOR_CMYK):
      //    {
      //      if (planarConfiguration == PlanarConfigurationType.Contignous)
      //      {
      //        //imageType = ImageType.CMYK32_INTERLEAVED;
      //      }
      //      /*else
      //      if (planarConfiguration == PLANAR_CONFIGURATION_PLANAR)
      //      {
      //        imageType = ImageType.CMYK32_PLANAR;
      //      }*/
      //      else
      //      {
      //        throw new UnsupportedTypeException("Cannot handle planar configuration other than chunky for CMYK images.");
      //      }
      //      break;
      //    }
      //  default:
      //    {
      //      throw new UnsupportedTypeException("Unsupported color type: " + photometricInterpretation + ".");
      //    }
      //}


      //if (photometricInterpretation == PhotometricType.PALETTED)
      //{
      //  if (bitsPerPixel == 4)
      //  {
      //    //imageType = ImageType.PALETTED4;
      //  }
      //  else if (bitsPerPixel == 8)
      //  {
      //    //imageType = ImageType.PALETTED8;
      //  }
      //  else
      //  {
      //    throw new UnsupportedTypeException("Only paletted images with 4 or 8 bits per sample are supported.");
      //  }
      //}

    }
  }
}
